package com.jing.lock;

import java.util.concurrent.TimeUnit;


/**
 * 八种锁测试
 */
class Phone{
/*    public synchronized void sendEmail(){
        try {TimeUnit.SECONDS.sleep(2);} catch (InterruptedException e) {throw new RuntimeException(e);}
        System.out.println(Thread.currentThread().getName() + "\t发邮件");
    }*/
    public static synchronized void sendEmail(){
        try {TimeUnit.SECONDS.sleep(2);} catch (InterruptedException e) {throw new RuntimeException(e);}
        System.out.println(Thread.currentThread().getName() + "\t发邮件");
    }

    public static synchronized void sendSMS(){
        System.out.println(Thread.currentThread().getName() + "\t发短信");
    }

    public void hello(){
        System.out.println(Thread.currentThread().getName() + "\t hello");
    }

/*    public synchronized void sendSMS(){
        System.out.println(Thread.currentThread().getName() + "\t发短信");
    }*/
}



public class LockTest {
    public static void main(String[] args) {
        Phone phone1 = new Phone();
        Phone phone2 = new Phone();
        new Thread(() -> {
            phone1.sendEmail();
        },"A").start();

        new Thread(() -> {
            //phone1.sendSMS();
            //phone2.sendSMS();
            phone2.hello();
        }, "B").start();
    }
}
